@echo off
rem 创建jar包执行目录、解释器目录
set jarDir=execute
set interpreter=%jarDir%\interpreter
if not exist %interpreter% (
	md %interpreter%
	copy %JAVA_HOME%\bin\javaw.exe %interpreter% 
)

rem 复制jar包到jar包执行目录
copy /Y register-center\eureka-server\target\eureka-server.jar %jarDir%\eureka-server.jar

copy /Y api-gateway\target\api-gateway.jar %jarDir%\api-gateway.jar

copy /Y oauth-center\auth-server\target\auth-server.jar %jarDir%\auth-server.jar

copy /Y business-center\user-center\target\user-center.jar %jarDir%\user-center.jar

copy /Y business-center\file-center\target\file-center.jar %jarDir%\file-center.jar

copy /Y web-portal\back-center\target\back-center.jar %jarDir%\back-center.jar

copy /Y business-center\exam-center\target\exam-center.jar %jarDir%\exam-center.jar

copy /Y business-center\paper-center\target\paper-center.jar %jarDir%\paper-center.jar

copy /Y business-center\forum-center\target\forum-center.jar %jarDir%\forum-center.jar

copy /Y business-center\points-center\target\points-center.jar %jarDir%\points-center.jar

copy /Y business-center\signIn-center\target\signIn-center.jar %jarDir%\signIn-center.jar

copy /Y business-center\study-center\target\study-center.jar %jarDir%\study-center.jar

copy /Y business-center\task-center\target\task-center.jar %jarDir%\task-center.jar


setlocal enabledelayedexpansion
rem 服务启动优先队列
set priorityQueue[0]=eureka-server
set priorityQueue[1]=api-gateway
set priorityQueue[2]=auth-server
set priorityQueue[3]=user-center
set priorityQueue[4]=file-center
set priorityQueue[5]=back-center
set priorityQueue[6]=exam-center
set priorityQueue[7]=forum-center
set priorityQueue[8]=paper-center
set priorityQueue[9]=points-center
set priorityQueue[10]=signIn-center
set priorityQueue[11]=study-center
set priorityQueue[12]=task-center


for /l %%i in (0,1,12) do (
  ren %interpreter%\*.exe !priorityQueue[%%i]!.exe
  call :killServer !priorityQueue[%%i]!
  start %interpreter%\!priorityQueue[%%i]! -Dhudson.util.ProcessTree.disable=true -jar -Xms128m -Xmx128m -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCTimeStamps -XX:+PrintGCDetails %jarDir%\!priorityQueue[%%i]!.jar
  choice /t 15 /d y /n >nul
)

exit 0

rem 终止已运行的目标服务
:killServer
  for /f "skip=3 tokens=2" %%j in ('tasklist /fi "imagename eq %1.exe"') do @set "pid=%%j" (
	if not "%pid%"=="""" taskkill -PID %pid% /f
  )
  set pid=""
goto :eof